package com.hy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hy.Result.ResponseResult;
import com.hy.mapper.ArticlesMapper;
import com.hy.utils.QueryParam;
import com.hy.pojo.Articles;
import com.hy.service.ArticlesService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【articles】的数据库操作Service实现
* @createDate 2025-03-05 09:03:19
*/
@Service
public class ArticlesServiceImpl extends ServiceImpl<ArticlesMapper, Articles>
    implements ArticlesService {
    @Autowired
    private ArticlesMapper articlesMapper;
    @Override
    public ResponseResult findAll(QueryParam queryParam) {
//        PageHelper.startPage(pageNum, pageSize);
//        PageResponseResult articlesList = articlesMapper.findByTitleLike();

        PageHelper.startPage(queryParam.getPageNum(), queryParam.getPageSize());
        LambdaQueryWrapper<Articles> l = new LambdaQueryWrapper();

        if(StringUtils.isNotBlank(queryParam.getArticleTitle())){
            l.like(Articles::getArticleTitle,queryParam.getArticleTitle());
        }
        if(StringUtils.isNotBlank(queryParam.getArticleAuthor())){
            l.eq(Articles::getArticleAuthor,queryParam.getArticleAuthor());
        }
        if(StringUtils.isNotBlank(queryParam.getArticleCategory())){
            l.eq(Articles::getArticleCategory,queryParam.getArticleCategory());
        }
        List<Articles> articles = articlesMapper.selectList(l);
        PageInfo<Articles> pageInfo = new PageInfo<>(articles);

        return ResponseResult.okResult(200,"查询成功!",pageInfo);
    }
}



